<?php

class SessionHelper {
    
    public static function getSession($key, $prefix = ''){
        if(!empty($prefix)){
            $return = isset($_SESSION[$prefix][$key]) ? $_SESSION[$prefix][$key] : null;
            unset($_SESSION[$prefix][$key]);
        } else {
            $return = isset($_SESSION[$key]) ? $_SESSION[$key] : null;
        }
        return $return;
    }
    
    public static function saveSession($key, $value){
        $_SESSION[$key] = $value;
    }
    
    public static function existsSession($key){
        return isset($_SESSION[$key]) && !empty($_SESSION[$key]);
    }
    
    public static function deleteSession($key){
        unset($_SESSION[$key]);
    }
    
    public static function saveMessage($text, $type = 'success'){
        $_SESSION['message'] = array(
            'text' => $text,
            'type' => $type
        );
    }
    
    public static function getMessage(){
        if(isset($_SESSION['message'])){
            $ArMessage = $_SESSION['message'];
            unset($_SESSION['message']);
            return $ArMessage;
        }
        return array();
    }
    
    public static function existsMessage(){
        return isset($_SESSION['message']);
    }
    
    public static function addJavascripts($ArJavascript){
        if(!isset($_SESSION['js'])){
            $_SESSION['js'] = array();
        }
        $_SESSION['js'][] = $ArJavascript;
    }
    
    public static function getJavascript(){
        $ArJavascript = array();
        if(isset($_SESSION['js'])){
            $ArJavascript = $_SESSION['js'];
            unset($_SESSION['js']);
        }
        return $ArJavascript;
    }
}

?>
